package com.hitplane.core 
{
	
	import com.hitplane.interfaces.ICheckCollision;
	import com.hitplane.interfaces.ICollisionAble;
	
	/**
	 * @describe  	碰撞检测
	 * @author  	郑子华
	 * @website 	http://blog.sina.com.cn/zihua2007
	 * @time		... 
	 */
	public class CheckCollision implements ICheckCollision
	{
		//参与检测的对象集合
		private var _collisionArr:Array;
		
		public function CheckCollision() 
		{
			_collisionArr = new Array();
		}
		
		/* INTERFACE com.hitplane.interfaces.ICheckCollision */
		
		public function addCollisionObj(displayObj:ICollisionAble):void
		{
			var index:int = _collisionArr.indexOf(displayObj);
			if (index == -1) {
				_collisionArr.push(displayObj);
			}
		}
		
		public function removeCollisionObj(displayObj:ICollisionAble):ICollisionAble
		{
			var index:int = _collisionArr.indexOf(displayObj);
			var returnObj:ICollisionAble;
			if (index != -1) {
				returnObj=_collisionArr.splice(index, 1)[0];
			}
			return returnObj;
		}
		
		public function checkCollision():void
		{
			throw new Error("子类覆写");
		}
		
		protected function get collisionArr():Array { return _collisionArr; }
		
		protected function set collisionArr(value:Array):void 
		{
			_collisionArr = value;
		}
		
	}
	
}